<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取一个请求令牌</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="oauth.getrequestheader.html">« OAuth::getRequestHeader</a></li>
      <li style="float: right;"><a href="oauth.setauthtype.html">OAuth::setAuthType »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.oauth.html">OAuth</a></li>
    <li>获取一个请求令牌</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="oauth.getrequesttoken" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">OAuth::getRequestToken</h1>
  <p class="verinfo">(PECL OAuth &gt;= 0.99.1)</p><p class="refpurpose"><span class="refname">OAuth::getRequestToken</span> &mdash; <span class="dc-title">获取一个请求令牌</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-oauth.getrequesttoken-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>OAuth::getRequestToken</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$request_token_url</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$callback_url</code><span class="initializer"> = ?</span></span>): <span class="type">array</span></div>

  <p class="para rdfs-comment">
   从服务提供者那里获取一个请求令牌、secret 、以及一些附带的响应参数。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-oauth.getrequesttoken-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">request_token_url</code></dt>

     <dd>

      <p class="para">
       请求令牌 API 的 URL。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">callback_url</code></dt>

     <dd>

      <p class="para">
       OAuth 回调 URL。 如果传递了 <code class="parameter">callback_url</code> 且为空值，则将其设置为“oob”即到 OAuth 2009.1 咨询的地址。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-oauth.getrequesttoken-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功则返回一个包含解析过了的 OAuth 响应的数组，失败则返回 <strong><code>false</code></strong> 。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-oauth.getrequesttoken-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>1.0.0</td>
       <td>
        以前失败时返回 <strong><code>null</code></strong>，而不是 <strong><code>false</code></strong>。
       </td>
      </tr>

      <tr>
       <td>0.99.9</td>
       <td>
       增加 <code class="parameter">callback_url</code> 参数。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-oauth.getrequesttoken-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5315">
    <p><strong>示例 #1 <span class="function"><strong>OAuth::getRequestToken()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$oauth&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">OAuth</span><span style="color: #007700">(</span><span style="color: #0000BB">OAUTH_CONSUMER_KEY</span><span style="color: #007700">,</span><span style="color: #0000BB">OAUTH_CONSUMER_SECRET</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$request_token_info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$oauth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getRequestToken</span><span style="color: #007700">(</span><span style="color: #DD0000">"https://example.com/oauth/request_token"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(</span><span style="color: #0000BB">$request_token_info</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$request_token_info</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;</span><span style="color: #DD0000">"Failed&nbsp;fetching&nbsp;request&nbsp;token,&nbsp;response&nbsp;was:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$oauth</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getLastResponse</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}&nbsp;catch(</span><span style="color: #0000BB">OAuthException&nbsp;$E</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Response:&nbsp;"</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$E</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">lastResponse&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [oauth_token] =&gt; some_token
    [oauth_token_secret] =&gt; some_token_secret
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-oauth.getrequesttoken-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="oauth.getlastresponse.html" class="methodname" rel="rdfs-seeAlso">OAuth::getLastResponse()</a> - 获取最后一次的响应</span></li>
    <li class="member"><span class="methodname"><a href="oauth.getlastresponseinfo.html" class="methodname" rel="rdfs-seeAlso">OAuth::getLastResponseInfo()</a> - 获取关于最后一次响应的 HTTP 信息</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>